{extend name="public/base" /}
{block name='content'}
{include file='public/content_header' /}
<style>
    .layui-form-label{
        width: 160px;
    }
    .goods-li {
        float: left;
        opacity: 1;
        position: relative;
    }

    .goods-img {
        width: 80px;
        height: 80px;
        padding: 4px;
    }
    .goods-img-del-x {
        position: absolute;
        z-index: 100;
        top: -4px;
        right: -2px;
        width: 20px;
        height: 20px;
        font-size: 16px;
        line-height: 16px;
        color: #fff;
        text-align: center;
        cursor: pointer;
        background: hsla(0, 0%, 60%, .6);
        border-radius: 10px;
    }
    .layui-likeedit {
      height: 300px; /* 设置你想要的高度 */
    }
</style>
<div class="layui-col-md12">
    <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" >
            <div class="layui-form" lay-filter="">
               <div class="layui-form-item" style="margin-bottom:0;">
                   <label class="layui-form-label">图标：</label>
                   <div class="layui-input-inline">
                       <div style="height:80px;line-height:80px">
                            <input name="image" type="hidden" value="{$config.image}">
                            {if !empty($config.image)}
                            <div class="goods-img-add" style="display: none" ></div>
                            <div class="goods-li">
                                <img class="goods-img" src="{$config.image}">
                                <a class="goods-img-del-x" style="display: none">x</a>
                            </div>
                            {else}
                            <div class="goods-img-add" ></div>
                            {/if}
                        </div>
                   </div>
               </div>
               <div class="layui-form-item" style="margin-bottom:0;">
                   <label class="layui-form-label">内容：</label>
                   <div class="layui-input-inline" style="width: 70%;">
                       <textarea  name="content" id="content" lay-verify="content" class="field-content">{$config.content}</textarea>
                   </div>
               </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                         <button class="layui-btn layui-bg-blue" lay-submit lay-filter="addSublime">提交</button>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </div>
</div>
<script>
layui.config({
    version:"{$front_version}",
    base: '/static/plug/layui-admin/dist/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index', 'form','likeedit','like'], function(){
    var $ = layui.$
        ,form = layui.form
        ,like = layui.like
        ,likeedit = layui.likeedit;

    // 监听提交
    form.on('submit(addSublime)', function(data){
        console.log(data.field)
        layui.$.ajax({
            url: '{:url("shop_config/welfaremall")}'
            , data: data.field
            , type: 'post'
            , success: function (res) {
                if(res.code === 1) {
                    layer.msg(res.msg, {
                        offset: '15px'
                        ,icon: 1
                        ,time: 1000
                    });
                    return false;
                }
            }
        });
        return false;
    });

    //富文本上传图片
        likeedit.set({
            uploadImage: {
                url: "{:url('file/image')}",
                type: 'post'
            }
        })
        var content = likeedit.build('content'); //建立编辑器
        form.verify({
            content: function() {
                likeedit.sync(content)
            }
        })

    //上传图片
    like.imageUpload('.goods-img-add', function (uri, element) {
        var html = '<div class="goods-li">\n' +
            '<img class="goods-img" ' +
            'src="' + uri[0] + '">' +
            '<a class="goods-img-del-x" style="display: none">x</a>' +
            '</div>';
        element.prev().val(like.getUrlFileName(uri[0], '{$storageUrl}'));
        element.parent().append(html);
        element.css('display','none');
    }, true);

    //删除图片
    $(document).on('click', '.goods-img-del-x', function () {
        $(this).parent().siblings('input').val('');
        $(this).parent().prev().css('display','block');
        $(this).parent().remove();
    });
    //显示图片
    $(document).on('click', '.goods-img', function () {
        var image = $(this).attr('src');
        like.showImg(image,600);
    });
    //删除按钮的显示与隐藏
    $(document).on('mouseover', '.goods-img', function () {
        $(this).next().show();
    });
    $(document).on('mouseout', '.goods-img', function () {
        $(this).next().hide();
    });
    $(document).on('mouseover', '.goods-img-del-x', function () {
        $(this).show();
    });
    $(document).on('mouseout', '.goods-img-del-x', function () {
        $(this).hide();
    });
    form.render();
});
</script>
{/block}

